<template>
	<view>
		<action-bar backTitle="返回" title="更多操作"></action-bar>
		<form>
			<view class="cu-form-group" @click="turn_to_code_page()">
				<view class="title">记账邀请</view>
				<view class="icon cuIcon-right"></view>
			</view>
			<view class="cu-form-group" @click="updateBook()">
				<view class="title">修改账本</view>
				<view class="icon cuIcon-right"></view>
			</view>
			<view class="cu-form-group" @click="deleteBook()">
				<view class="title">删除账本</view>
				<view class="icon cuIcon-right"></view>
			</view>
			<view class="cu-form-group" @click="changeBookBelong()">
				<view class="title">更改账本所有人</view>
				<view class="icon cuIcon-right"></view>
			</view>
		</form>
	</view>
</template>

<script>
	import {hasPermisson} from '../../common/permission.js'
	export default {
		data() {
			return {
				bookId: '',
				bookUserId: null
			}
		},
		onLoad(option) {
			this.bookId = option.id
			this.bookUserId = option.uid
			
		},
		methods: {
			hasPermisson,
			updateBook() {
				if (this.hasPermisson()) {
					uni.navigateTo({url: `./create?id=${this.bookId}&op=1`})
				} else {
					this.$message.info('没有权限')
				}
			},
			deleteBook() {
				if (this.hasPermisson()) {
					uni.showModal({title: '确认要删除吗?\n删除后无法恢复', success: res=> {
						if (res.confirm) {
							this.$request({
								url: `/account/${this.bookId}`,
								method: 'DELETE'
							}).then(res => {
								console.log(res);
								uni.showToast({title: '删除成功'})
								setTimeout(() => {
									uni.reLaunch({url: './index'})
								}, 800)
							})
						}
					}})
				} else {
					this.$message.info('没有权限')
				}
			},
			changeBookBelong() {
				this.$message.info('暂不支持')
			},
			turn_to_code_page() {
				uni.navigateTo({url: `../code/invite?bookId=${this.bookId}`})
			}
		}
	}
</script>

<style>
</style>
